<?php
include("header.php");

$term = $_GET["term"];
$disciplineID = $_GET["id"];
$collegeID = $_GET["college"];
$days = $_GET["days"];
$startTime = $_GET["startTime"];
$endTime = $_GET["endTime"];
$bok = $_GET["bok"];

$daysarray = str_split($days);
$days = implode("%",$daysarray);

$sql = "SELECT distinct cl.classID as id,cli.longName AS name FROM college c, discipline d, classes cl, classes_info cli, sections s, days ds WHERE d.college_collegeID=c.collegeID AND cl.discipline_discID=d.discID AND cli.classes_classID=cl.classID AND s.classID=cl.classID AND ds.sectionID=s.sectionID "; 

if($collegeID){
	$sql .= "AND c.collegeID = $collegeID ";
}
if($disciplineID){
	$sql .= "AND d.discID = $disciplineID ";
}
if($days){
	$sql .= "AND ds.days LIKE '$days' ";
}
if($startTime){}
if($bok != 'ALL'){
	$sql .= "AND cli.bok = '$bok' ";
}

$sql .=  "ORDER BY name ASC";

$r = mysql_query($sql, $con);

$classes = array();
if(mysql_num_rows($r)) {
	while($class = mysql_fetch_assoc($r)) {
		$classes[] = $class;
	}
}

header('Content-type: application/json');
echo json_encode(array('classes'=>$classes));
//echo json_encode($classes);

include("footer.php");
?>
